package triangle.dj;

import java.io.*;
import java.text.*;
import java.util.*;
import jxl.*;
import jxl.read.biff.BiffException;
import triangle.datastructures.*;
import jargs.gnu.CmdLineParser;

public class DjGeneratorRunner {

	public static void main(String [] args)
	{
		try {
			
			DjGenerator djg = new DjGenerator();
			if (args.length == 0)
				djg.generateDj();
			else 
			{
				try {
					CmdLineParser parser = new CmdLineParser();
					CmdLineParser.Option templateFile = parser.addStringOption('f', "templateFile");
			        CmdLineParser.Option dontMarkSundayAsPledge = parser.addBooleanOption("notSundayAsPledge");
			        parser.parse(args);
			        
			        String templateExcelFile = (String) parser.getOptionValue(templateFile, djg.getTemplate());
			        Boolean sunValue =
			            (Boolean)parser.getOptionValue(dontMarkSundayAsPledge);
			        if (sunValue == null)
			        	djg = new DjGenerator(templateExcelFile);
			        else
			        	djg = new DjGenerator(templateExcelFile, false);
			        djg.generateDj();
		        }
		        catch ( CmdLineParser.OptionException e ) {
		            System.err.println(e.getMessage());
		            printUsage();
		            System.exit(2);
		        }
			}
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
	}
	
	public static void printUsage()
	{
		System.err.println("Usage : java -jar dj_gen.java [{-f/template templateExcelFilename}] [-sundayAsPledge]");
		System.err.println("  templateExcelFilename is the excel file where you want your new DJ excel file to copy from");
		System.err.println("  notSundayAsPledge puts pledge's name instead of 'Pledge' on Sundays");
		System.err.println("  If you have no idea what this is about, just run java -jar dj_gen.java");
		System.err.println("  I'm too lazy to really write a documentation...");
	}
}
